$(function() {
//	var html = "";
//	html += '<div class="locate">';
//	html += '<div class="locate-info">';
//	html += '<p class="name"><span class="names"></span><span class="tels"></span></p>';
//	html += '<p class="address"></p>';
//	html += '</div>';
//	html += '<p style="width: 92%;border-top: 1px solid #ddd;margin-left: 3%;"></p>';
//	html += '<div class="loacte-edit">';
//	html += '<span class="mui-icon mui-icon-checkmarkempty"></span>当前默认';
//	html += '<div class="edit-right">';
//	html += '<span class="mui-icon mui-icon-compose"></span><span class="edit">编辑</span> &nbsp;&nbsp;<span class="mui-icon mui-icon-trash"></span><span class="delate">删除</span>';
//	html += '</div>';
//	html += '</div>';
//	html += '</div>';

	$('.save').click(function() {

		if($('.inpu-name').val() == '') {
			//$.toast('姓名不能为空', 'cancel');
			mui.toast('姓名不能为空', {
				duration: 'long',
				type: 'div'
			})
			return false;
		} else if($('.inpu-tel').val() == '') {
			//$.toast('电话不能为空', 'cancel');
			mui.toast('电话不能为空', {
				duration: 'long',
				type: 'div'
			})
			return false;
		} else if(!(/^1(3|4|5|7|8)\d{9}$/.test($('.inpu-tel').val()))) {
			//$.toast('电话格式错误', 'cancel');
			mui.toast('电话格式错误', {
				duration: 'long',
				type: 'div'
			})
			return false;
		} else if($('.inpu-address').val() == '') {
			mui.toast('送货地址不能为空', {
				duration: 'long',
				type: 'div'
			})
			return false;
		} else {
			mui.toast('保存成功', {
				duration: 'long',
				type: 'div'
			})
			var myname = $('.inpu-name').val();
			var mytel = $('.inpu-tel').val();
			var myaddress = $('.inpu-address').val();
			util.setLocalStorage('name', myname);
			util.setLocalStorage('tel', mytel);
			util.setLocalStorage('address', myaddress);

			//$('.addressbox').append(html)

			window.location.href = 'locate.html'
		}

	})

	//13294111632

	//声明 保存获取地址节面的value
	var tel = util.getLocalStorage('tel');
	var name = util.getLocalStorage('name');
	var address = util.getLocalStorage('address')

	//注入地址管理编辑界面的值
	$('.names').text(name);
	$('.tels').text(tel)
	$('.address').text(address)

	//声明获取管理界面 value值
	var name1 = util.getLocalStorage('name1');
	var tel1 = util.getLocalStorage('tel1');
	var address1 = util.getLocalStorage('address1');

	//注入编辑界面的数据
	$('.inpu-name').val(name1);
	$('.inpu-tel').val(tel1);
	$('.inpu-address').val(address1);
	//alert(myname1);

	//地址界面 删除地址
	$('.delate').click(function() {

		mui.confirm('您确定要删除吗？', '确认删除', function(e) {
			if(e.index == 1) {
				//删除地址  清除缓存
				$('.delate').parents('.locate').hide();
				util.setLocalStorage('tel', '');
				util.setLocalStorage('name', '');
				util.setLocalStorage('address', '');
				// window.localStorage.clear();
				//mui.toast('MUI 没有得到你的认可,继续加油!');
			}
			//e.index == 0 ? mui.toast('感谢您的支持!') : mui.toast('MUI 没有得到你的认可,继续加油!')
		})
	})

	//管理地址 编辑
	$('.edit').click(function() {
		var myname1 = $('.names').text();
		var mytel1 = $('.tels').text();
		var myaddress1 = $('.address').text();

		//设定缓存值
		util.setLocalStorage('tel1', mytel1);
		util.setLocalStorage('name1', myname1);
		util.setLocalStorage('address1', myaddress1);
		//注入修改界面的值

		window.location.href = 'editlocate.html'
	})

	$('.newaddress').click(function() {
		util.setLocalStorage('tel1', '');
		util.setLocalStorage('name1', '');
		util.setLocalStorage('address1', '');

	})

})